/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 *
 */
import { BaseEvent, EventAdditional, EventBody, EventHead, MetricEventType } from './base-event.js';

export enum MetricLogType {
  DEBUG = 'debug',
  INFO = 'info',
  WARN = 'warn',
  ERROR = 'error',
  DETAIL = 'detail',
}

export class LogEventAdditional implements EventAdditional {
  logType: MetricLogType;
  durationId?: string;
  continualId?: string;
  parent?: string;
  children: string[];

  constructor(logType: MetricLogType) {
    this.logType = logType;
    this.children = [];
  }
}

export class LogEvent extends BaseEvent {
  additional: LogEventAdditional;

  constructor(id: string, name: string, description: string, pid: number, tid: string, type: MetricLogType) {
    super(new EventHead(id, name, description, MetricEventType.LOG), new EventBody(pid, tid));
    this.additional = new LogEventAdditional(type);
  }

  getLogType() {
    return this.additional.logType;
  }

  setLogType(type: MetricLogType) {
    this.additional.logType = type;
  }

  getDurationId() {
    return this.additional.durationId;
  }

  setDurationId(durationId: string) {
    this.additional.durationId = durationId;
  }

  getContinualId() {
    return this.additional.continualId;
  }

  setContinualId(continualId: string) {
    this.additional.continualId = continualId;
  }

  addChild(id?: string) {
    if (!id) {
      return;
    }
    if (this.additional.children.indexOf(id) === -1) {
      this.additional.children.push(id);
    }
  }

  setParent(id: string) {
    if (this.additional.parent) {
      return;
    }
    this.additional.parent = id;
  }
}
